package com.gitee.melin.bee.core.jdbc.enums;

import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.gitee.melin.bee.core.enums.BaseStringEnum;
import com.gitee.melin.bee.core.enums.jackson.JacksonEnumStringSerializer;

/** 数据类型 */
@JsonSerialize(using = JacksonEnumStringSerializer.class)
public enum DataSourceType implements BaseStringEnum {
    HIVE("Hive", "org.apache.hive.jdbc.HiveDriver", 10000),
    INCEPTOR("Inceptor", "org.apache.hive.jdbc.HiveDriver", 10000), // 星环 Inceptor
    MYSQL("MySQL", "com.mysql.cj.jdbc.Driver", 3306),
    TIDB("MySQL", "com.mysql.cj.jdbc.Driver", 4000),
    MARIADB("Mariadb", "org.mariadb.jdbc.Driver", 3306),
    DORIS("Doris", "com.mysql.cj.jdbc.Driver", 9030),
    STARROCKS("StarRocks", "com.mysql.cj.jdbc.Driver", 9030),
    POSTGRESQL("PostgreSQL", "org.postgresql.Driver", 5432, true),
    DB2("DB2", "com.ibm.db2.jcc.DB2Driver", 51000, true),
    SQLSERVER("SQLServer", "com.microsoft.sqlserver.jdbc.SQLServerDriver", 1433, true),
    ORACLE("Oracle", "oracle.jdbc.driver.OracleDriver", 1521),
    GAUSSDWS("GaussDWS", "com.huawei.gauss200.jdbc.Driver", 8000, true),
    GBASE8A("Gbase8a", "com.gbase.jdbc.Driver", 5258, true),
    GREENPLUM("Greenplum", "org.postgresql.Driver", 5432, true),
    HASHDATA("HashData", "org.postgresql.Driver", 5432, true),
    HANA("Hana", "com.sap.db.jdbc.Driver", 30015),
    DAMENG("DaMeng", "dm.jdbc.driver.DmDriver", 5236),
    KINGBASEES("KingbaseES", "com.kingbase8.Driver", 54321, true),
    OCEANBASE("OceanBase", "com.alipay.oceanbase.jdbc.Driver", -1),
    MAXCOMPUTE("MaxCompute", "com.aliyun.odps.jdbc.OdpsDriver", -1),
    CLICKHOUSE("ClickHouse", "com.clickhouse.jdbc.ClickHouseDriver", 8123),
    REDSHIFT("Redshift", "com.amazon.redshift.jdbc42.Driver", 5439, true),
    SNOWFLAKE("Snowflake", "net.snowflake.client.jdbc.SnowflakeDriver", -1, true),
    CASSANDRA("Cassandra", "com.simba.cassandra.jdbc42.Driver", 9042),
    ELASTICSEARCH("ElasticSearch", "", -1),
    MONGODB("MongoDB", "", -1),
    S3("S3", "", -1),
    MINIO("Minio", "", -1),
    OSS("OSS", "", -1),
    COS("COS", "", -1),
    OBS("OBS", "", -1),
    FTP("FTP", "", -1),
    KAFKA("Kafka", "", -1),
    PAIMON("Paimon", "", -1),
    ICEBRG("Iceberg", "", -1);

    private String name;

    private String driverClass;

    private Integer defaultPort = -1;

    /* 数据库支持database 和 schema，例如sqlserver, pg等数据库 */
    private boolean supportDatabase = false;

    DataSourceType(String name) {
        this.name = name;
    }

    DataSourceType(String name, String driverClass, Integer defaultPort) {
        this.name = name;
        this.driverClass = driverClass;
        this.defaultPort = defaultPort;
    }

    DataSourceType(String name, String driverClass, Integer defaultPort, boolean supportDatabase) {
        this.name = name;
        this.driverClass = driverClass;
        this.defaultPort = defaultPort;
        this.supportDatabase = supportDatabase;
    }

    @JsonValue
    @Override
    public String getValue() {
        return this.name;
    }

    @Override
    public String toString() {
        return this.getValue();
    }

    public String getDriverClass() {
        return driverClass;
    }

    public boolean isSupportDatabase() {
        return supportDatabase;
    }

    public boolean isFileSystem() {
        return this == FTP || this == S3 || this == MINIO || this == OSS || this == COS || this == OBS;
    }
}
